
 var html = "";


function RenderCarts(res){
   
            //console.log(res);
            //alert("渲染吧！！");
            this.init(res);
            //alert("渲染结束");
        
            new Carts();
}

$.extend(RenderCarts.prototype,{
    init : function(res){
        this.car_goods_list = $(".car-goods-list");
        this.renderCarsList(res);
    },
    renderCarsList : function(list){
        
        var goodsArray = [];
        var ls = localStorage.getItem("carts");
        //console.log(ls);
        var la = JSON.parse(ls === null ?"[]":ls);
        // console.log(list);
        var list = JSON.parse(list);
         //console.log(list.goods_list);
        $.each(list.goods_list,function(index,goods_item){
            //console.log(goods_item.goods_id);
            $.each(la,function(index,cars_item){
               if(goods_item.goods_id == cars_item.id){
                   goods_item.goods_count = cars_item.count;
                   goodsArray.push(goods_item);
               }
            })
        })
        //console.log(goodsArray);
       

            $.each(goodsArray,function(index,item){
                //console.log(item);
                 //console.log(html);
    
                html +=`<table class="car-goods-box">
                <tbody>
                    <tr class="car-product">
                        <td class="car-col-select">
                            <a href="#" class="cat-img">
                                <img src="${item.goods_path}"/>
                            </a>
                            
                        </td>
                        <td class="car-td2">
                            <a href="#" class="cat-detail">
                              <p class="car-detail-name">${item.goods_name}</p>
                              <p class="car-detail-desc">${item.goods_detail}</p>
                            </a>
                        </td>
                        <td class="car-td3">
                            <p>￥${item.goods_price}</p>
                        </td>
                        <td class="car-td4" data-id="${item.goods_id}">
                            <button class="reduce-cars">-</button>
                            <div class="cat-xiaoji-count">${item.goods_count}</div>
                            <button class="add-cars">+</button>
                        </td>
                        <td class="car-td5">
                            <span class="car-xiaoji-price">￥${item.goods_price*item.goods_count}</span>
                        </td>
                        <td class="car-td6">
                            --
                        </td>
                    </tr>
                </tbody>
            </table>`;
            })
           
            $(this.car_goods_list).html(html); 
        //console.log(html);
       
        
    }
})



$.ajax("./data/data1.json").then(function(res){
    //console.log(res);
        new RenderCarts(res);
        // alert("这个时候应该调用购物车了")
        // alert("大兄弟，调用购物车了");
        //new Carts();

    
})
$.ajax("./data/data2.json").then(function(res){
    new RenderCarts(res);
    // alert("大兄弟，调用购物车了");
    //new Carts();
})
// console.log(html);
//export default new RenderCarts();